<template>
  <div>
    <el-drawer :visible.sync="drawer" direction="rtl" size="50%" :with-header="false" :width="700">
      <div class="drawer_box">
        <div class="drawer_title">
          <div class="drawer_t">
            <div class="drawer_t_l">
              <img class="drawer_t_l_img" src="/static/skin/herodoo/main/platform/home/img/piliangoumai.png" alt="" />
              查看订单
            </div>
            <img class="drawer_t_r" src="/static/skin/herodoo/main/platform/home/img/guanbi.png" alt=""
              @click="drawer = false" />
          </div>
        </div>
        <div class="drawer_content">
          <div class="content-box">
            <div class="label">订单编号:</div>
            <div class="desc">
              {{ messageList.Code }}
              <div class="states" :style="getState(messageList.STATUSID, 'STATUS').style">
                {{ messageList.STATUS }}
              </div>
            </div>
          </div>
          <div class="content-box">
            <div class="label">权益名称:</div>
            <div class="desc name" @click="drawerUpDetail">
              {{ messageList.Name }}
            </div>
          </div>
          <div class="content-box" v-if="messageList.TypeID == 2">
            <div class="label">包含权益:</div>
            <div class="desc">
              <div class="rightsList">
                <div class="rights_son_box" v-if="alreadyList && alreadyList != false">
                  <div class="rights_son" v-for="item in alreadyList" :key="item.ID">
                    <div class="rights_son_title">{{ item.Name }}</div>
                  </div>
                </div>
                <div class="rights_son_box" v-if="buyList && buyList != false">
                  <div class="rights_son" v-for="item in buyList" :key="item.ID">
                    <div class="rights_son_title">{{ item.Name }}</div>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <div class="content-box">
            <div class="label">买家:</div>
            <div class="desc">{{ messageList.PurchaseName }}</div>
          </div>
          <div class="content-box">
            <div class="label">购买数量:</div>
            <div class="desc">{{ messageList.Quantity }}</div>
          </div>
          <div class="content-box">
            <div class="label">平台价格:</div>
            <div class="desc">{{ messageList.CostPrice }}</div>
          </div>
          <div class="content-box">
            <div class="label">下单金额(元):</div>
            <div class="desc">{{ messageList.TotalPrice }}</div>
          </div>
          <div class="content-box">
            <div class="label">购买渠道:</div>
            <div class="desc">{{ messageList.PlatformID }}</div>
          </div>
          <div class="content-box">
            <div class="label">服务方:</div>
            <div class="desc">{{ messageList.ServiceCompanyName }}</div>
          </div>
          <div class="content-box">
            <div class="label">使用积分:</div>
            <div class="desc">{{ messageList.Integration }}</div>
          </div>
          <div class="content-box">
            <div class="label">卖家:</div>
            <div class="desc">{{ messageList.PurchaseCompanyName }}</div>
          </div>
          <div class="content-box" v-if="messageList.STATUSID != 20">
            <div class="label">下单时间:</div>
            <div class="desc">{{ messageList.CreateTime }}</div>
          </div>
          <div class="content-box" v-if="messageList.STATUSID == 20">
            <div class="label">取消时间:</div>
            <div class="desc">{{ messageList.UpdateTime }}</div>
          </div>
        </div>
      </div>
    </el-drawer>
    <!-- 查看权益详情 -->
    <rights-detail :octopus="octopus" ref="rightsDetail"></rights-detail>
  </div>
</template>

<script>
import orderStatus from "../../../../../static/skin/default/base/js/orderStatus";
import AssigeCar from "../Components/assigeCar.vue";
import rightsDetail from "./rightsDetail.vue";
export default {
  name: "look_dialog",
  components: {
    rightsDetail
  },
  props: {
    messageList: {
      type: Object,
      default: {}
    }
  },
  data() {
    return {
      octopus: this.$parent.octopus,
      drawer: false,
      states: {
        name: "订单状态",
        is_index: 0,
        is_type: "",
        arr: orderStatus
      },
      buyList: [],
      alreadyList: []
    };
  },
  methods: {
    drawerOp() {
      this.drawer = true;
      this.buyList = [];
      this.alreadyList = [];

      if (this.messageList.TypeID == 2) {
        this.getCompileData().then(res => {
          res.map(v => {
            if (v.CompanyID == this.messageList.CompanyID) {
              this.alreadyList.push(v);
            } else {
              this.buyList.push(v);
            }
          });
        });
      }
    },
    getState(i, type) {
      let obj = {};
      if (type == "index") {
        this.states.arr.filter((item, o) => {
          if (o == i) {
            obj = item;
          }
        });
      }
      if (type == "id" || type == "type") {
        this.states.arr.filter(item => {
          if (item[type] == i) {
            obj = item;
          }
        });
      }
      if (type.toLowerCase() == "status") {
        this.states.arr.filter(item => {
          if (item.name == i) {
            obj = item;
          }
        });
      }
      obj.style = `color:${obj.color};background:${obj.bgColor};borderColor:${obj.color
        }`;
      return obj;
    },
    // 展示权益详情
    drawerUpDetail() {
      this.$refs.rightsDetail.init(this.messageList.EquityID);
      this.$refs.rightsDetail.drawerOp(this.alreadyList, this.buyList);
    },
    // 获取权益详情
    getCompileData() {
      return new Promise((resolve, reject) => {
        let o = this;
        o.octopus.request.api.post(
          "/Octopus/Engine/List",
          {
            id: 1184,
            cellData: [
              { name: "CostPrice" }, // 平台价格
              { name: "CompanyID" }, // 子权益公司ID
              { name: "FlagList" }, // 权益标签
              { name: "FlagListName" }, // 权益标签
              { name: "ID" }, // ID
              { name: "Name" }, // 权益标题
              { name: "SalePrice" }, // 市场价格
              { name: "SoldQuantity" }, // 已售数量
              { name: "TypeID" }, // 权益类型
              { name: "ExpireTime" }, // 到期时间
              { name: "EffectiveTime" }, // 生效时间
              { name: "InventoryQuantity" }, // 库存数量
              { name: "SoldQuantity" }, // 已售数量
              { name: "EquityCount" }, // 权益数量
              { name: "EquityServiceRate" }, // 小程序服务费
              { name: "PlatformServiceRate" }, // 平台服务费
              { name: "UserCount" } // 使用人数
            ],
            paramData: {
              ID: o.messageList.EquityID
            }
          },
          data => {
            if (data.status.code == 200) {
              resolve(data.content.queryData);
            } else {
              o.octopus.tips.error(data);
              reject(false);
            }
          }
        );
      });
    }
  }
};
</script>
<style scoped>
.drawer_box {
  padding: 3rem 0.8rem 3rem 0;
  height: calc(100% - 5rem);
  display: flex;
  flex-direction: column;
}

.drawer_title {
  box-shadow: 0px 5px 5px rgb(230 228 228 / 30%);
  padding: 1rem 0;
}

.title {
  font-size: 1.8rem;
  font-weight: bold;
  padding: 1rem 0;
}

.drawer_t {
  padding: 0 2.8rem;
  display: flex;
  justify-content: space-between;
}

.drawer_t_l {
  display: flex;
  align-items: center;
  font-size: 2rem;
  font-weight: bold;
}

.drawer_t_l_img {
  width: 2.8rem;
  margin-right: 1rem;
}

.drawer_t_r {
  width: 3rem;
  height: 3rem;
  cursor: pointer;
}

.button_box {
  margin-top: 1rem;
  padding: 0 3rem;
  display: flex;
}

.drawer_content {
  overflow-y: auto;
  margin-top: 1.5rem;
  height: calc(100vh - 13rem);
  padding: 0 3rem;
  width: 100%;
  padding-bottom: 1rem;
}

.drawer_content .title {
  font-size: 1.8rem;
  font-weight: bold;
}

.drawer_content .title2 {
  font-size: 1.8rem;
}

.drawer_content .driver-title {
  margin-top: 1em;
}

.content-box {
  display: flex;
  align-items: center;
  margin: 2rem 0 2rem 2em;
}

.mt-10 {
  margin-top: 20px;
}

.content-box .label {
  width: 25%;
}

.content-box .label .label-bold {
  font-size: 1.8rem;
  font-weight: bold;
}

.content-box .desc {
  /* flex: 1; */
  display: flex;
  flex-direction: row;
  align-items: center;
}

.name {
  color: #288ffd;
  text-decoration: underline;
  cursor: pointer;
}

.states {
  /* font-size: 1vw; */
  padding: 5px 10px;
  border: 1px solid #000;
  border-radius: 5px;
  margin-left: 20px;
}

.drawer_footer {
  display: flex;
  justify-content: flex-end;
  align-content: center;
}

.drawer_footer .footer-btn {
  line-height: 4rem;
  background-color: #f78c51;
  color: #fff;
  margin: 0 1rem;
  padding: 0 3rem;
  border-radius: 0.5rem;
  cursor: pointer;
}

.drawer_footer .reject {
  background-color: #2e3037;
}

.end {
  display: flex;
  justify-content: flex-end;
}

>>>.el-pagination.is-background .el-pager li:not(.disabled).active {
  background-color: #ff8a36;
}
</style>
